package org.gis.mvc.view;


import java.util.HashMap;
import java.util.Map;
import org.gis.mapserver.base.ContextType;
import org.gis.mapserver.responsewriter.ResponseWriter;
import org.gis.mvc.bean.RequestBean;
import org.gis.utils.activator.Activator;
import org.springframework.web.servlet.View;


/**
 *
 * @author gus
 */
public class ResultViewFactory 
{
    private static final Map<ContextType, Class<? extends ViewBase>> viewMapping = 
        new HashMap<ContextType, Class<? extends ViewBase>>();
    
    static
    {
        viewMapping.put(ContextType.PNG, PNGResultView.class);
    }
    
    public static View createView(RequestBean bean, ResponseWriter writer) throws Exception
    {
        if( bean == null )
        {
            throw new IllegalArgumentException("bean");
        }
        if(writer == null)
        {
            throw new IllegalArgumentException("writer");
        }
        
        Class clazz = viewMapping.get(bean.getContextType());
        
        ViewBase view = (ViewBase) Activator.instance(clazz);
        view.setWriter(writer);
        view.afterInitialize();
        return view;
    }
    
}
